import { request } from '@umijs/max';

/** 分页查询所有用户 GET /system/user/list */
export async function getUserList(params?: API.QueryUserPageParams) {
  return request<API.QueryPageResp<API.User>>('/system/user/list', {
    method: 'GET',
    params,
  });
}

/** 新增用户 POST /system/user/add */
export async function addUser(params: API.User) {
  return request<API.Resp>('/system/user/add', {
    method: 'POST',
    data: params,
  });
}

/** 修改用户 POST /system/user/update */
export async function updateUser(params: API.User) {
  return request<API.Resp>('/system/user/update', {
    method: 'POST',
    data: params,
  });
}

/** 获取单个用户 GET /system/user/get/{id} */
export async function getUserById(id: React.Key) {
  return request<API.Resp<API.User>>(`/system/user/get/${id}`, {
    method: 'GET',
  });
}

/** 删除用户 POST /system/user/delete */
export async function deleteUserById(id: React.Key) {
  return request<API.Resp>(`/system/user/delete`, {
    method: 'POST',
    params: {
      id,
    },
  });
}

/** 批量删除用户 POST /system/user/deleteUsersByIds */
export async function deleteUsersByIdList(idList: React.Key[]) {
  return request<API.Resp>(`/system/user/deleteUsersByIds`, {
    method: 'POST',
    data: idList,
  });
}

/** 重置密码 POST /system/user/resetPassword/{id} */
export async function resetPassword(id: React.Key) {
  return request<API.Resp>(`/system/user/resetPassword/${id}`, {
    method: 'POST',
  });
}

/** 查询用户与角色关联关系 GET /system/user/getUserRole/{id} */
export async function getUserRole(id: React.Key) {
  return request<API.Resp<number[]>>(`/system/user/getUserRole/${id}`, {
    method: 'GET',
  });
}

/** 赋予角色数据权限 POST /system/user/addUserRole */
export async function addUserRole(params: API.AddUserRoleParams) {
  return request<API.Resp>('/system/user/addUserRole', {
    method: 'POST',
    data: params,
  });
}
